package longrise.phone.com.bjjt_jyb.compensate;

import android.content.Context;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.longrise.android.FormParameter;
import com.longrise.android.FrameworkManager;
import com.longrise.android.LFView;

import longrise.phone.com.bjjt_jyb.R;


/**
 * 进入快处快赔的安全提示，Created by Administrator on 2016/5/12.
 */
public class QRCodeView extends LFView implements View.OnClickListener {
    private Context context = null;
    private View view = null;
    private LinearLayout hn_btn_back;
    private Button bt_qrcodesure;
    private int fromwhere=-1;


    public QRCodeView(Context c) {
        super(c);
        this.context = c;
    }
    public QRCodeView(Context c,int fromwhere) {
        super(c);
        this.context = c;
        this.fromwhere=fromwhere;
    }

    @Override
    public void refreshByTime() {

    }

    @Override
    public FormParameter getFormParameter() {
        FormParameter fp = new FormParameter();
        fp.setShowtitle(false);
        return fp;
    }

    @Override
    public void refresh() {

    }

    @Override
    public View getView() {
        return view;
    }

    @Override
    public void init() {
        initView();
        regEvent(true);
    }

    private void initView() {
        view = View.inflate(context, R.layout.view_qrcode, null);
        bt_qrcodesure = (Button) view.findViewById(R.id.bt_qrcodesure);
        hn_btn_back = (LinearLayout) view.findViewById(R.id.hn_btn_back);
        TextView tv_title = (TextView) view.findViewById(R.id.tv_title);
        TextView tv_mycode = (TextView) view.findViewById(R.id.tv_mycode);
        tv_title.setText("我的二维码");
        if(fromwhere!=-1){
            bt_qrcodesure.setVisibility(View.GONE);
            tv_mycode.setVisibility(View.GONE);
        }else {
            bt_qrcodesure.setVisibility(View.VISIBLE);
            tv_mycode.setVisibility(View.VISIBLE);
        }
    }

    private void regEvent(boolean b) {
        if (null != bt_qrcodesure) {
            bt_qrcodesure.setOnClickListener(b ? this : null);
        }

        if (null != hn_btn_back) {
            hn_btn_back.setOnClickListener(b ? this : null);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt_qrcodesure:
                SafeWarningView safewarningview = new SafeWarningView(context);
                FrameworkManager.getInstance().showNewForm(context, safewarningview);
                break;
            case R.id.hn_btn_back:
                closeForm();
                OnDestroy();
                break;
        }
    }
}
